home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles Flirt Up Your Life! (German)
/
Singles Flirt Up Your Life.iso
/
data1.cab
/
Statemachine
/
swimChar.lua
< prev
next >
Wrap
Text File
|
2004-01-29
|
7KB
|
272 lines
-- elaine walk state machine
beginStateMachine()
onEnter(function(msg)
print("swimChar enter ------------------------------------------");
local pool = retrieveStateObject("pool")
if (pool) then
getParent().startActivity("swim", pool);
end
end )
onExit(function(msg)
print("swimChar exit ------------------------------------------");
local pool = retrieveStateObject("pool")
if (pool) then
getParent().stopActivity("swim", pool);
end
end )
onMsg("goAway", function(msg)
print("onMsg goAway(swim)-----------------------------------------------------------");
if (isWalking()) then return end;
local minDist = random(1,10);
local target = getParent().findPointNear(minDist, 10.0);
if (target) then
getParent().queueWalkActionPoint("pm_swim", target, true);
else
print("goAway(swim) no target");
end
end )
-- onMsg("leavePool", function(msg)
--
-- local exitPoints = pool.getExitPoints(getParent());
-- for p = 1, getn(exitPoints) do
-- print(" exitPoints " .. p);
-- local actionPoint = exitPoints[p];
--
-- -- get the walk state object
-- if (walkToActionPoint(actionPoint)) then
-- print("leave pool");
-- storeData("exit", true);
-- return
-- end
-- end
--
-- end )
onMsg("queue", function(msg)
nextAction();
print("stop swim");
end )
-- state("goAway")
-- onEnter(function(msg)
-- print("goAway onEnter");
-- local minDist = random(1,10);
-- local target = getParent().findPointNear(minDist, 10.0);
-- if (target) then
-- getParent().queueWalkActionPoint("pm_swim", target, true);
-- else
-- print("no target");
-- end
-- end )
-- stand
state("stand")
onEnter(function(msg)
startAnimation("swimmingStand");
sendDelayedMsgThis("makeDrop", 1000);
actionComplete();
getParent().loopSound("swimOnPlace");
end )
onExit(function(msg)
getParent().stopSound("swimOnPlace");
end )
onMsg("makeDrop", function(msg)
getParent().createWaterDrop(0.2, 200);
sendDelayedMsgThis("makeDrop", 1000);
end )
onMsg("end", function(msg)
startAnimation("swimmingStand");
actionComplete();
end )
-- walk
state("walk")
onEnter(function(msg)
print("walk onEnter " .. getParent().getCharacterName());
local pool = retrieveStateObject("pool")
getParent().loopSound("swimLoop");
local walkAnim = "swimmingSlow";
storeData("walkAnim", walkAnim);
startWalk(walkAnim, "swimmingStand");
if (pool.isCharacterLeavingPool(getParent())) then
-- local groundActionPoint = getParent().walkSO.getWantedActionPoint();
-- storeData("groundActionPoint", getParent().walkSO.getWantedActionPoint());
-- storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
local topEntry = getParent().getActivityQueueEntry(0);
if (topEntry) then
storeData("groundActionPoint", topEntry.getTarget());
storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
end
local exitPoints = pool.getExitPoints(getParent());
for p = 1, getn(exitPoints) do
print(" exitPoints " .. p);
local actionPoint = exitPoints[p];
-- get the walk state object
if (walkToActionPoint(actionPoint)) then
print("leave pool");
storeData("exit", true);
return
end
end
print("no path found");
--getParent().setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
else
print("stay in pool");
end
storeData("exit", false);
sendDelayedMsgThis("makeDrop", 250);
end )
onExit(function(msg)
getParent().stopSound("swimLoop");
end )
-- target changed durring walk
onMsg("targetChanged", function(msg)
print("target changed durring walk " .. getParent().getCharacterName());
local pool = retrieveStateObject("pool")
if (pool.isCharacterLeavingPool(getParent())) then
-- local groundActionPoint = getParent().walkSO.getWantedActionPoint();
-- storeData("groundActionPoint", getParent().walkSO.getWantedActionPoint());
local topEntry = getParent().getActivityQueueEntry(0);
if (topEntry) then
storeData("groundActionPoint", topEntry.getTarget());
storeData("afterWalkMsg", getParent().getAfterWalkMsg(0));
end
local exitPoints = pool.getExitPoints(getParent());
for p = 1, getn(exitPoints) do
print(" exitPoints " .. p);
local actionPoint = exitPoints[p];
-- get the walk state object
if (walkToActionPoint(actionPoint)) then
print("leave pool");
storeData("exit", true);
return
end
end
print("no exit point found");
storeData("exit", false);
else
print("stay in pool");
storeData("exit", false);
end
end )
onMsg("makeDrop", function(msg)
getParent().createWaterDrop(0.2, 500);
sendDelayedMsgThis("makeDrop", 250);
end )
onMsg("next", function(msg)
if testCancel() then
print("next testCancel == true");
stopWalk();
nextAction();
else
local pool = retrieveStateObject("pool")
local walkAnim = retrieveData("walkAnim", "swimming");
local newWalkAnim = "swimming";
if (pool.isCharacterMovingToEdge(getParent(), 1.5)) then newWalkAnim = "swimmingSlow"; end;
storeData("walkAnim", newWalkAnim);
--startWalk(newWalkAnim, "swimmingStand");
if (newWalkAnim == walkAnim) then
print("next - startWalk " .. newWalkAnim);
startWalk(newWalkAnim, "swimmingStand");
else
print("next - startWalk changed" .. walkAnim .. " -> " .. newWalkAnim);
startWalk(newWalkAnim, "swimmingStand", 1000);
end
print("next - swim anim " .. newWalkAnim);
end
end )
onMsg("end", function(msg)
if (retrieveData("exit", false) == true) then
print("end -> exit");
setState("exitSwim");
else
print("end -> stay");
nextAction();
end
end )
-- walk
state("exitSwim")
onEnter(function(msg)
print("exitSwim " .. getParent().getCharacterName());
getParent().replaceQueueEntry(0, "pm_exitPool");
local groundActionPoint = retrieveData("groundActionPoint");
if (groundActionPoint) then
print("exitSwim queueWalkActionPoint1 queue:" .. getParent().getActivityQueueCount());
getParent().pushWalkActionPoint("pm_walk", groundActionPoint, true, retrieveData("afterWalkMsg"));
-- getParent().queueWalkActionPoint("pm_walk", groundActionPoint, true);
print("exitSwim queueWalkActionPoint2 queue:" .. getParent().getActivityQueueCount());
end
exitStateMachine();
end)
endStateMachine()